# Contributor: Mike Crute <mike@crute.us>
# Contributor: Nicolas Lorin <androw95220@gmail.com>
# Maintainer: Nicolas Lorin <androw95220@gmail.com>
pkgname=stayrtr
pkgver=0.5.1
pkgrel=0
pkgdesc="Simple RPKI-To-Router server. (Hard fork of GoRTR)"
url="https://github.com/bgp/stayrtr"
arch="all"
license="BSD-3-Clause"
options="net chmod-clean"
makedepends="go"
pkgusers="stayrtr"
pkggroups="stayrtr"
install="$pkgname.pre-install"
subpackages="$pkgname-openrc"
source="$pkgname-$pkgver.tar.gz::https://github.com/bgp/stayrtr/archive/v$pkgver.tar.gz
	$pkgname.initd
	$pkgname.confd
	"

export GOCACHE="${GOCACHE:-"$srcdir/go-cache"}"
export GOTMPDIR="${GOTMPDIR:-"$srcdir"}"
export GOMODCACHE="${GOMODCACHE:-"$srcdir/go"}"

build() {
	export CGO_ENABLED=1
	make \
		OUTPUT_STAYRTR=dist/stayrtr \
		OUTPUT_RTRDUMP=dist/rtrdump \
		OUTPUT_RTRMON=dist/rtrmon \
		STAYRTR_VERSION=$pkgver \
		LDFLAGS='"-X main.version=$(STAYRTR_VERSION) -X main.buildinfos=$(BUILDINFOS)"' \
		build-stayrtr build-rtrdump build-rtrmon
}

check() {
	make test
}

package() {
	install -Dm755 dist/stayrtr "$pkgdir"/usr/bin/$pkgname
	install -Dm755 dist/rtrdump "$pkgdir"/usr/bin/rtrdump
	install -Dm755 dist/rtrmon "$pkgdir"/usr/bin/rtrmon

	install -Dm755 "$srcdir"/$pkgname.initd "$pkgdir"/etc/init.d/$pkgname
	install -Dm644 "$srcdir"/$pkgname.confd "$pkgdir"/etc/conf.d/$pkgname
}

sha512sums="
a155045d423bf4da20a07699df096c38e6ace23ad9f93bbc7180135ec5bc367eed1ad349f9033ceda5521afba7d455d19afd0bc8d95b7376c91b4b051bd4a51f  stayrtr-0.5.1.tar.gz
926dd3d3c3851d2b787ed7ae42ba1dcc54b432e5cb9ab6a30fa8eee1df19b48f50b37b37b84262d83e53031993ac39bd68a87bd9e47752eca49c104e0b1e7897  stayrtr.initd
73d8e1465332287ec035872777caa3c60072ae62a359d2f1374275901423d120300ebcfca22a7ca7c1131056183f39a9fb19ad1b08678d3bde13b383874d4a7d  stayrtr.confd
"
